app.controller("mySettingCtrl",function($scope,$timeout, $state,$http,$ionicLoading,timePickerService){
    //用户数据
    var userInfo = JSON.parse(localStorage.getItem("UserInfo"));
    // var getPath = JSON.parse(localStorage.getItem("getPath"));
    $scope.user = {
        userEmail:"",
        userTel:"",
        userAddr:"",
        // userBirth:"",
        userPost:""
    };
    angular.element(document).ready(function () {
        //初始化
        // var birth = "";
        // if(userInfo.userBirth){
        //     birth = userInfo.userBirth.substr(0,10);
        // }else{
        //     birth = new Date().Format("yyyy-MM-dd");
        // }
        $scope.user = {
            userEmail:userInfo.userEmail || "",
            userTel:userInfo.userTel || "",
            userAddr:userInfo.userAddr || "",
            // userBirth:birth,
            userPost:userInfo.userPost || ""
        };
        //头像
        $scope.userHeader = userInfo.userHeader;
        // $scope.user.userBirth = userInfo.userBirth.substr(0,10) || "";
    })
    $scope.saveInfo = function () {
        var url = getPath.url+getPath.name+"/app/updateUser";
        $scope.user = angular.copy($scope.user);
        var userEmail = $scope.user.userEmail || "";
        var userTel = $scope.user.userTel || "";
        var userAddr = $scope.user.userAddr || "";
        // var userBirth = birthDay.substr(0,10) || "";
        var userPost = $scope.user.userPost || "";
        var param = {
            userId:userInfo.userId,
            noteIndex:1,
            userEmail:userEmail,
            userTel:userTel,
            userAddr:userAddr,
            // userBirth:userBirth,
            userPost:userPost
        }
        userInfo.userEmail = userEmail;
        userInfo.userTel = userTel;
        userInfo.userAddr = userAddr;
        // userInfo.userBirth = userBirth;
        userInfo.userPost = userPost;
        $http({
            url: url,
            method: "POST",
            data:param,
            headers:{'Content-Type':'application/x-www-form-urlencoded'}
        }).success(function(data){
                var res = data.resultBean;
                if(data.resultCode==200){
                    $ionicLoading.show({
                        template: "保存成功！",
                        duration:3000
                    });
                    localStorage.setItem("UserInfo",JSON.stringify(userInfo));
                }else{
                    $ionicLoading.show({
                        template: "保存失败！",
                        duration:3000
                    });
                }
            })
            .error(function(){
                $ionicLoading.show({
                    template: "系统错误，请联系管理员！",
                    duration:3000
                });
            });
    }
    //设置头像
    $scope.goSettingImg = function () {
        $state.go("home.settingImg");
    }
});